﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;

namespace Sherwood.Configuration
{
    /// <summary>
    /// Represents a repository of config files.
    /// </summary>
    public interface IConfigRepository
    {
        /// <summary>
        /// Read a configuration file as text. Returns null if file does not exist.
        /// </summary>
        /// <param name="fileName">A relative or virtual filename (depending on repository type)</param>
        ///<exception cref="ArgumentNullException"></exception>
        TextReader CreateTextReaderSafe(string fileName);

        /// <summary>
        /// Write a configuration back to the repository using a text writer. Remember to close after writing is finished.
        /// </summary>
        /// <param name="fileName">A releative or virtual filename</param>
        /// <returns>A text writer that may be used to write the configuration</returns>
        TextWriter CreateTextWriter(string fileName);

        /// <summary>
        /// Reads a list of available file names inside a repository path
        /// </summary>
        /// <param name="path">The (virtual) path to look into</param>
        /// <param name="searchPattern">The search pattern to filter on</param>
        IEnumerable<string> GetFileNames(string path, string searchPattern);

        /// <summary>
        /// Verifies if a given (virtual) path is valid / exists
        /// </summary>
        /// <param name="path">The (virtual) path to look into</param>
        bool IsPathValid(string path);
    }
}